package org.freedoit.server.service.task;

import java.util.logging.Logger;

import org.freedoit.server.om.Task;
import org.freedoit.server.service.ServiceManager;
import org.freedoit.server.service.data.TaskReturnResult;
import org.freedoit.server.util.Utils;
import org.freedoit.shared.data.SharedTask;

public class AddTaskServlet extends TaskServlet {

	/**
	 * 
	 */

	private static final Logger log = Logger.getLogger(AddTaskServlet.class.getName());
	private static final long serialVersionUID = -4511087566999049359L;

	protected void workOnTask(SharedTask sharedTask, Long currentUserId, TaskReturnResult result,
			Long timestamp) {
		// TODO Auto-generated method stub
		log.warning("adding task");
		Task task = Utils.fromSharedData(sharedTask);
		if (ServiceManager.addNewTask(task, currentUserId, null, null, timestamp)) {
			result.setCode(TaskReturnResult.CODE_OK);
			result.setTimestamp(timestamp.longValue());
			result.setTaskID(task.getTaskId());
		} else {
			result.setCode(TaskReturnResult.CODE_INVALID_DATA);
		}

		log.warning("" + result.getCode());
	}

}
